/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.managed;

import beans.ejb.FantasyteamFacade;
import entities.Fantasyleague;
import entities.Fantasyteam;
import entities.Fantasyuser;
import java.util.Iterator;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author stumbledog
 */
@Named(value = "editSetting")
@RequestScoped
public class EditSetting {
    @EJB
    private FantasyteamFacade fantasyteamFacade;
    private Fantasyleague currentLeague;
    private Fantasyuser user;
    private Fantasyteam myTeam;

    public Fantasyteam getMyTeam() {
        return myTeam;
    }

    public void setMyTeam(Fantasyteam myTeam) {
        this.myTeam = myTeam;
    }
    /**
     * Creates a new instance of EditSetting
     */
    public EditSetting() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        AccountBean b = (AccountBean) request.getSession().getAttribute("accountBean");
        currentLeague = b.getCurrentLeague();
        user = b.getAccount();
        
        Iterator<Fantasyteam> itr = currentLeague.getFantasyteamCollection().iterator();
        while(itr.hasNext()){
            Fantasyteam tmp = itr.next();
            if(tmp.getUserId().equals(user)){
                myTeam = tmp;
            }
        }
    }
    
    public String submit() {
        fantasyteamFacade.edit(myTeam);
        return "league";
    }

    public String cancel() {
        return "league";
    }
}
